<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.drag_drop.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction("saveWidgets");
$xajax->registerFunction("removeWidget");

/* Notizzettel */
$xajax->registerFunction("newNotice");
$xajax->registerFunction("noticeForm");
$xajax->registerFunction("resetNotice");
$xajax->registerFunction("delNotice");

function convertToVars($query_string) {
	$vars = array();
	if (!is_array($query_string)) {
		$arr_vars = explode('&',$query_string);
		foreach ($arr_vars as $value) {
			$arr_vars2 = explode('=',$value);
			$vars[$arr_vars2[0]] = urldecode($arr_vars2[1]);
		}
	} else {
		reset($query_string);
		while (list($key, $value) = each ($query_string)) {
			$vars[$key] = $value;
		}
	}
	return $vars;
}

function cleanName($str) {
	return str_replace("'", '', $str);
}

function removeWidget($widget_id) {
	global $db;

	$ajax = new xajaxResponse();
	if(empty($_SESSION['customer_id']))
		$ajax->script("window.location.href = '".FILENAME_LOGIN."';");
	else {
		$id = explode('-', cleanName($widget_id));
		$db->db_query("UPDATE
							".TABLE_ADMIN_START_PAGE."
						SET
							status = '0'
						WHERE
							id = '".$id[1]."'");
	}
	return $ajax;
}

function holdSession() {
	$ajax = new xajaxResponse();

	return;
}

function saveWidgets($spalte, $widget_id, $widget_name, $sort, $farbe, $open) {
	global $db;

	$ajax = new xajaxResponse();

	if(empty($_SESSION['customer_id']))
		$ajax->script("window.location.href = '".FILENAME_LOGIN."';");
	else {

		if($widget_id != 'intro') {

			$id = explode('-', cleanName($widget_id));
			$spalte = explode('-', cleanName($spalte));

			$db->db_query("UPDATE
							".TABLE_ADMIN_START_PAGE."
						SET
							widget_name = '".$widget_name."',
							spalte = '".$spalte[1]."',
							sort_id = '".$sort."',
							offen = '".$open."',
							farbe = '".cleanName($farbe)."'
						WHERE
							id = '".$id[1]."'");

		} else {
			$db->db_query("UPDATE
							".TABLE_ADMIN_START_PAGE."
						SET
							widget_name = '".$widget_name."',
							offen = '".$open."',
							farbe = '".cleanName($farbe)."'
						WHERE
							id = '1'");
		}
	}
	return $ajax;
}

function noticeForm($get) {
	global $db;

	$get = convertToVars($get);

	$db->db_query("INSERT INTO ".TABLE_ADMIN_START_PAGE_NOTICE." (notice_title, notice_desc, date_added) VALUES ('".$get['notice_title']."', '".$get['notice_text']."', NOW())");
	$ajax = new xajaxResponse();
	$ajax->script('location.reload()');
	return $ajax;
}

function delNotice($id) {
	global $db;

	$db->db_query("DELETE FROM ".TABLE_ADMIN_START_PAGE_NOTICE." WHERE notice_id = '".$id."'");

	$ajax = new xajaxResponse();
	$ajax->script('jQuery(".notice_'.$id.'").fadeOut();');
	$ajax->script('setTimeout(\'jQuery(".notice_'.$id.'").remove()\', 1500)');
	return $ajax;
}

function resetNotice() {
	$ajax = new xajaxResponse();

	$ajax->assign('notice_zone', 'innerHTML', '<a class="button" href="javascript:void(0)" onclick="xajax_newNotice()">neue Notiz</a>');

	return $ajax;
}

function newNotice() {
	$ajax = new xajaxResponse();

	$content  = '<form id="new_notice_form">';
	$content .=	'	<table width="100%">';
	$content .=	'		<tr>';
	$content .=	'			<td>Titel:</td>';
	$content .=	'			<td align="left"><input name="notice_title" value="" type="text" /></td>';
	$content .=	'		</tr>';
	$content .=	'		<tr>';
	$content .=	'			<td>Text:</td>';
	$content .=	'			<td align="left"><textarea cols="" rows="" name="notice_text"></textarea></td>';
	$content .=	'		</tr>';
	$content .=	'		<tr>';
	$content .=	'			<td align="right" colspan="2"><a href="javascript:void(0)" onclick="xajax_resetNotice()" class="button">doch nicht</a> <a href="javascript:void(0)" class="button" onclick="xajax_noticeForm(xajax.getFormValues(\'new_notice_form\'));">Speichern</a></td>';
	$content .=	'		</tr>';
	$content .=	'	</table>';
	$content .= '</form>';

	$ajax->assign('notice_zone', 'innerHTML', $content);

	return $ajax;
}
?>